<?php
/**
 * Created by PhpStorm.
 * User: 柳迪
 * Date: 2018/7/12
 * Time: 9:02
 */

namespace app\api\controller;


use think\Controller;

class Masters extends Controller
{
    public function getList()
    {
        $result=db('masters')->field('masterid,mastername,masterpic,masterintro')->order('masterflag desc')->limit(6)->select();
        for($i=0;$i<count($result);$i++)
        {
            $result_video=db('videos')->field('vid,vname,vfile,vintro,masterid')->where('masterid',$result[$i]['masterid'])->select();
            $result[$i]['videolist']=$result_video;
        }
        echo json_encode($result);
        die();
    }

    public function getDetail()
    {
        if(input('?id'))
        {
            if(!db('masters')->find(input('id')))
            {
                echo json_encode(['status'=>0,'message'=>'id错误。']);
                die();
            }
            $masterid=input('id');
            $result=db('masters')->field('masterid,mastername,masterpic,masterintro')->find($masterid);
            $result_video=db('videos')->field('vid,vname,vfile,vintro,masterid')->where('masterid',$masterid)->select();
            $result['videolist']=$result_video;
            echo json_encode($result);
            die();
        }
        else
        {
            echo json_encode(['status'=>0,'message'=>'参数错误']);
            die();
        }
    }


}